<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../layui/layui.js"></script>
    <script src="../js/jquery-1.8.0.min.js"></script>
    <script src="../js/ajax.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../css/addPage.css">
</head>

<body>
<form action="" class="layui-form layui-form-pane">
    <input type="hidden" name="id" id="id" placeholder="请输入标题" autocomplete="off" class="layui-input">
    <div class="layui-form-item">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-block">
            <input type="text" name="commodityName" maxlength="30" id="commodityName" required lay-verify="required"
                   placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">供货商</label>
        <div class="layui-input-block">
            <select name="supplierId" id="supplierId" lay-verify="required" lay-search="">
                <option value="">请选择供货商</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单价</label>
        <div class="layui-input-block">
            <input type="text" name="price" id="price" maxlength="30" required lay-verify="required"
                   placeholder="请输入单价" autocomplete="off" class="layui-input" onblur="count()">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数量</label>
        <div class="layui-input-block">
            <input type="text" name="number" id="number" maxlength="30" required lay-verify="required"
                   placeholder="请输入数量" autocomplete="off" class="layui-input" onblur="count()">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">总价</label>
        <div class="layui-input-block">
            <input type="text" name="totalPrice" id="totalPrice" maxlength="30" required lay-verify="required"
                   placeholder="总价" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">验收结论</label>
        <div class="layui-input-block">
            <select name="conclusion" id="conclusion" lay-verify="required">
                <option value="1">通过</option>
                <option value="2">不通过</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="send" lay-submit lay-filter="AddOrUpdate">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="../js/host.js"></script>
<script>
    // var host = "http://192.168.9.199:8080/WarehouseManageMaven_war_exploded";
    //  var host = "http://192.168.9.156:8080";

    function count() {
        $("#totalPrice").val($("#price").val() * $("#number").val())
    }


    $.ajaxSetup({
        headers: {
            "token": localStorage.getItem("token")
        }
    });

    $(function () {
        layui.use(["table", "form"], function () {
            var table = layui.table;
            var form = layui.form;
            setTimeout(function () {
                form.render("select")
            }, 50)



            new ajax(host + "/supplierMvc/getSupplier", "get", {}, "json", function (data) {
                $.each(data, function (index, item) {
                    $("#supplierId").append("<option value='" + item.id + "'>" + item.supplierName + "</option>")
                })
            });

            form.render('select'); //刷新select选择框渲染
            form.on("submit(AddOrUpdate)", function (data) {
                var url = "addGoods";
                if ($("#id").val() != null && $("#id").val() != "") {
                    url = "updateGoods";
                }

                new ajax(host + "/" + url, "get", data.field, "json", function (data) {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                    parent.layer.msg('提交成功', {
                        icon: 1,
                        time: 2000
                    });
                });
                $.ajaxSettings.async = true;
                return false;
            })

        })
    })
</script>
</body>

</html>